﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using System.Data.SqlClient;

namespace QLTV.Forms.KhaiBao
{
    public partial class frmVesselType : BaseForm
    {
        public frmVesselType()
        {
            InitializeComponent();
            this.statusDataBar1.addTextChange(tblVesselTypeBindingSource);
            this.statusDataBar1.addTextChange(gridView1);
            this.statusDataBar1.AddControlPrint(gridControl1);
        }

        private void frmVesselType_Load(object sender, EventArgs e)
        {
            // TODO: This line of code loads data into the 'dsVessel.tblVesselType' table. You can move, or remove it, as needed.
            this.tblVesselTypeTableAdapter.Fill(this.dsVessel.tblVesselType);

        }

        private void statusDataBar1_NewClick(object sender, StatusDataBar.StatusDataBarArgs e)
        {
            this.tblVesselTypeBindingSource.AddNew();
        }

        private void statusDataBar1_UpdateClick(object sender, StatusDataBar.StatusDataBarArgs e)
        {
            this.tblVesselTypeBindingSource.EndEdit();
            this.tblVesselTypeTableAdapter.Update(dsVessel.tblVesselType);
            this.tblVesselTypeTableAdapter.Fill(this.dsVessel.tblVesselType);
        }

        private void statusDataBar1_UndoClick(object sender, StatusDataBar.StatusDataBarArgs e)
        {
            this.tblVesselTypeBindingSource.CancelEdit();
            this.tblVesselTypeTableAdapter.Fill(this.dsVessel.tblVesselType);
        }

        private void statusDataBar1_DeleteClick(object sender, StatusDataBar.StatusDataBarArgs e)
        {
            try
            {
                this.tblVesselTypeBindingSource.RemoveCurrent();
                this.tblVesselTypeTableAdapter.Update(dsVessel.tblVesselType);
                this.tblVesselTypeTableAdapter.Fill(this.dsVessel.tblVesselType);
            }
            catch (SqlException ex)
            {
                this.tblVesselTypeTableAdapter.Fill(this.dsVessel.tblVesselType);
                if (ex.ErrorCode == -2146232060)
                {
                    XtraMessageBox.Show("Dữ liệu đang được sử dụng vui lòng kiểm tra lại", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else
                {
                    XtraMessageBox.Show(ex.Message, "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
    }
}